package note.dao;

import java.util.List;

import note.dao.entity.Article;

import org.apache.ibatis.session.SqlSessionFactory;

import core.util.AbstractDao;
import core.util.StringHashMap;

public class ArticleDao extends AbstractDao {

	private String namespace = "article.";

	public ArticleDao(SqlSessionFactory sessionFactory) {
		super(sessionFactory);
	}

	public int listArticleSize(StringHashMap map) {
		map.put("is_count", 1);
		return ((Article) getObject(namespace + "listArticle", map)).cnt;
	}

	public List<Article> listArticle(StringHashMap map) {
		map.put("is_count", 0);
		return getList(namespace + "listArticle", map);
	}

	public void saveArticle(Article Article) {
		if (insert(namespace + "saveArticle", Article) != 0)
			Article.id = (Integer) getObject(namespace + "getIdOfArticle");
	}

	public int updateArticle(Article Article) {
		return update(namespace + "updateArticle", Article);
	}
	

	public int deleteArticle(Article Article) {
		return update(namespace + "deleteArticle", Article);
	}

	public Article getArticle(Article Article) {
		Object object = getObject(namespace + "getArticle", Article);
		return (object != null) ? (Article) object : null;
	}

}
